//
//  ZLLExceptionReport.m
//  ZLLCrashReportDemo
//
//  Created by 张亮亮 on 2018/3/31.
//  Copyright © 2018年 张亮亮. All rights reserved.
//

#import "ZLLExceptionReport.h"

@implementation ZLLExceptionReport

@end
/** The exception handler that was in place before we installed ours. */
static NSUncaughtExceptionHandler* g_previousUncaughtExceptionHandler;

/** Our custom excepetion handler.
 * Fetch the stack trace from the exception and write a report.
 *
 * @param exception The exception that was raised.
 */

static void handleException(NSException* exception) {

    // 异常的堆栈信息
    NSArray *stackArray = [exception callStackSymbols];
    
    // 出现异常的原因
    NSString *reason = [exception reason];
    
    // 异常名称
    NSString *name = [exception name];
    
    NSString *exceptionInfo = [NSString stringWithFormat:@"Exception reason：%@\nException name：%@\nException stack：%@",name, reason, stackArray];
    
    NSLog(@"exceptionInfo:%@", exceptionInfo);

    if (g_previousUncaughtExceptionHandler != NULL)
    {
        g_previousUncaughtExceptionHandler(exception);
    }
}
void installExceptionHandler(void) {
      g_previousUncaughtExceptionHandler = NSGetUncaughtExceptionHandler();
    NSSetUncaughtExceptionHandler(&handleException);
}
